package com.zs.games.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zs.games.resultTool.CimResponse;
import com.zs.games.param.*;
import com.zs.games.service.UserDynamicService;
import com.zs.games.vo.UserDynamicVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/dynamic")
@Api(tags = "动态管理")
public class DynamicController {

    @Autowired
    private UserDynamicService dynamicService;

    @GetMapping("/pageList")
    @ApiOperation("分页获取动态列表")
    @ApiOperationSupport(order = 1)
    public CimResponse<IPage<UserDynamicVo>> pageList(PageQuery param) {
        return CimResponse.okData(dynamicService.getPage(param));
    }

    @PostMapping("/addDynamic")
    @ApiOperation("创建动态")
    @ApiOperationSupport(order = 3)
    public CimResponse<Boolean> createDynamic(@RequestBody UserAddDynamicParam param) {
        return CimResponse.okData(dynamicService.createDynamic(param));
    }

    @PostMapping("/delete")
    @ApiOperation("删除动态")
    @ApiOperationSupport(order = 5)
    public CimResponse<Boolean> deleteGameNews(@RequestBody @Validated IdParam param) {
        return CimResponse.okData(dynamicService.deleteDynamic(param.getId()));
    }
    @PostMapping("/addPraise")
    @ApiOperation("点赞动态")
    @ApiOperationSupport(order = 6)
    public CimResponse<Boolean> addPraiseGameNews(@RequestBody @Validated IdParam param) {
        return CimResponse.okData(dynamicService.praiseDynamic(param.getId()));
    }
    @PostMapping("/cancelPraise")
    @ApiOperation("取消点赞")
    @ApiOperationSupport(order = 7)
    public CimResponse<Boolean> cancelPraiseGameNews(@RequestBody @Validated IdParam param) {
        return CimResponse.okData(dynamicService.cancelPraiseDynamic(param.getId()));
    }

    @PostMapping("/addComment")
    @ApiOperation("评论动态")
    @ApiOperationSupport(order = 10)
    public CimResponse<Boolean> addComment(@RequestBody @Validated UserCommentParam param) {
        return CimResponse.okData(dynamicService.commentDynamic(param));
    }
    @PostMapping("/deleteComment")
    @ApiOperation("删除评论")
    @ApiOperationSupport(order = 11)
    public CimResponse<Boolean> deleteComment(@RequestBody @Validated IdParam param) {
        return CimResponse.okData(dynamicService.deleteCommentDynamic(param.getId()));
    }
}
